<?php

chdir('../');

require('includes/setUp.php');
  
/**
 * TODO: user check, data check
 */
if ($user == null )
  globalFunc::redirect(WebRoot.'index.php?errMsg='.rawurlencode(T_('You have to be logged on!')));

try {
  $album = new Album();
  $album = $db->find('Album',$_GET['id']);

  if ($album->ProtectionName == 'private' && !$album->AllowedUsers->contains($user))
    globalFunc::redirect(WebRoot.'index.php?errMsg='.rawurlencode(T_('You don\'t have access to this album!')));

  $user->addFavoriteAlbum($album);
  $db->flush();

} catch (Exception $ex) {
  globalFunc::redirect(WebRoot.'index.php?errMsg='.rawurlencode($ex->getMessage()));
}

globalFunc::redirect();
